package com.softtown.modules.workflow.controller;

import com.softtown.common.annotation.LogOperation;
import com.softtown.common.utils.Result;
import com.softtown.modules.workflow.dto.SwfTaskDTO;
import com.softtown.modules.workflow.entity.SwfTaskEntity;
import com.softtown.modules.workflow.service.SwfTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author: Dingyayong
 * @Date: 2019/8/22 17:38
 * @Description:
 */
@RestController
@RequestMapping("swf/task")
@Api(tags = "获取审批任务")
public class SwfTaskController {

    @Resource
    private SwfTaskService swfTaskService;

    /**
     * 获取任务审批段
     *
     * @param swfTaskDTO 审批任务DTO
     * @return com.softtown.common.utils.Result<com.softtown.modules.entity.SwfTaskEntity>
     * @Author Dingyayong
     * @Date 2020/4/13 17:20
     */
    @PostMapping("getTaskPhase")
    @ApiOperation("获取任务审批段")
    @LogOperation("获取任务审批段")
    public Result<SwfTaskEntity> getTaskPhase(@RequestBody SwfTaskDTO swfTaskDTO) {
        SwfTaskEntity
                swfTaskEntity = swfTaskService.getSwfTaskByApplByprocInstId(swfTaskDTO.getCompId(), swfTaskDTO.getProcInstId());
        return new Result<SwfTaskEntity>().ok(swfTaskEntity);
    }

    /**
     * 获取待我审批中的审批上一审批人
     *
     * @param swfTaskDTO 审批任务DTO
     * @return com.softtown.common.utils.Result<com.softtown.modules.entity.SwfTaskEntity>
     * @Author Dingyayong
     * @Date 2020/4/13 17:21
     */
    @PostMapping("getswfHstAprvLast")
    @ApiOperation("获取待我审批中的审批上一审批人")
    @LogOperation("获取待我审批中的审批上一审批人")
    public Result<SwfTaskEntity> getswfHstAprvLast(@RequestBody SwfTaskDTO swfTaskDTO) {
        SwfTaskEntity
                swfTaskEntity = swfTaskService.getswfHstAprvLast(swfTaskDTO);
        return new Result<SwfTaskEntity>().ok(swfTaskEntity);
    }

    /**
     * 获取当前任务审批段
     *
     * @param swfTaskDTO 审批任务DTO
     * @return com.softtown.common.utils.Result<com.softtown.modules.entity.SwfTaskEntity>
     * @Author Dingyayong
     * @Date 2020/4/13 17:22
     */
    @PostMapping("getTaskPhaseEnd")
    @ApiOperation("获取当前任务审批段")
    @LogOperation("获取当前任务审批段")
    public Result<SwfTaskEntity> getTaskPhaseEnd(@RequestBody SwfTaskDTO swfTaskDTO) {
        SwfTaskEntity
                swfTaskEntity = swfTaskService.getNowTaskPhase(swfTaskDTO.getCompId(), swfTaskDTO.getProcInstId());
        return new Result<SwfTaskEntity>().ok(swfTaskEntity);
    }

    /**
     * 获取当前审批人信息
     *
     * @param swfTaskDTO 审批任务DTO
     * @return com.softtown.common.utils.Result<com.softtown.modules.entity.SwfTaskEntity>
     * @Author Dingyayong
     * @Date 2020/4/13 17:22
     */
    @PostMapping("getNewApproveInfo")
    @ApiOperation("获取当前审批人信息")
    @LogOperation("获取当前审批人信息")
    public Result<SwfTaskEntity> getNewApproveInfo(@RequestBody SwfTaskDTO swfTaskDTO) {
        SwfTaskEntity
                swfTaskEntity = swfTaskService.getNewApproveInfo(swfTaskDTO.getCompId(), swfTaskDTO.getProcInstId());
        return new Result<SwfTaskEntity>().ok(swfTaskEntity);
    }
}
